<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <script src="js/jquery-3.3.1.min.js"></script>
    <title>修改密码</title>

    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
</head>

<body class="hold-transition login-page">

<div class="login-box">
    <div class="login-box-body" style="padding: 40px">
            <input type="hidden" name="id" id="name" value="${loginUser.id}"/>
            <div class="form-group has-feedback">
                旧密码：<input type="password" id="oldPwd" name="oldPwd" class="form-control" required>
            </div>
            <div class="form-group has-feedback">
                新密码：<input type="password" id="newPwd" name="newPwd" class="form-control" required>
            </div>
            <div class="form-group has-feedback">
                确认密码：<input type="password" id="newPwd2" name="newPwd2" class="form-control" required>
            </div>
            <div class="col-xs-5">
                <button type="button" class="btn btn-primary btn-block btn-flat" onclick="submit()">确认修改</button>
            </div>
            <div class="col-xs-4">
                <button type="button" class="btn btn-primary btn-block btn-flat" onclick="history.back(-1);">取消</button>
            </div>
    </div>
</div>
<script type="text/javascript">
    function submit() {
        debugger;
        var userId=document.getElementById("name").value;
        var oldPwd=document.getElementById("oldPwd").value;
        var newPwd=document.getElementById("newPwd").value;
        var newPwd2=document.getElementById("newPwd2").value;
        if(newPwd!==newPwd2){
            alert("密码不一致，请重新输入！");
            return;
        }
        $.get(
            "system/user",
            {operation:"changePwd",
                userId:userId,
                oldPwd:oldPwd,
                newPwd:newPwd
            },
            function (data) {
                alert(data)
                // $("#nspan").html(data);
                //密码修改后需要重新登录
                if(data=='修改成功，请重新登录！'){
                    location.href="${pageContext.request.contextPath}/system/user?operation=toLogin";
                }
            }
        )
    }
</script>
</body>

</html>